package nameless.aistudy.api.role.user.subjects.english.vocabulary;

import nameless.aistudy.domain.model.subjects.english.vocabulary.book.VocabularyBook;
import nameless.aistudy.domain.model.subjects.english.vocabulary.dto.VocabularyBookDTO;

import nameless.aistudy.domain.service.subjects.english.vocabulary.VocabularyInsertService;
import nameless.aistudy.domain.service.subjects.english.vocabulary.VocabularyService;
import org.springframework.http.ResponseEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user/subject/english/vocabulary")
@CrossOrigin(origins = "http://localhost:8080")
public class VocabularyController {

    @Autowired
    private VocabularyInsertService vocabularyInsertService;

    /**
     * 接口1：创建词汇本
     * 请求示例：{"bookName":"考研核心词汇","description":"2025考研必备"}
     */
    @PostMapping("/book")
    public ResponseEntity<VocabularyBook> createBook(@RequestBody VocabularyBookDTO dto) {
        VocabularyBook book = vocabularyInsertService.createVocabularyBook(dto);
        return ResponseEntity.ok(book); // 返回带ID的词汇本
//        return  null;
    }

    /**
     * 接口2：向词汇本添加单词
     * 请求示例：{"bookId":1,"words":[{"spell":"apple",...}]}
     */
    @PostMapping("/book/words")
    public ResponseEntity<String> addWords(@RequestBody VocabularyBookDTO dto) {
        vocabularyInsertService.addWordsToBook(dto);
        return ResponseEntity.ok("单词已成功添加到词汇本");
//        return null;
    }
}
